package javatools;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

public class MaptestMine {
    public static void main(String[] args) {
        MaptestMine mine=new MaptestMine();
        mine.testHashMap(1000000);
    }

    public void testHashMap(int size){
        int index;
        String [] keys=new String[size];
        Map<String, String> map=new HashMap<>();
        Random random=new Random();

        //Hashmap insert time
        long start=System.currentTimeMillis();
        for (int i=0;i<size;i++){
            keys[i]= UUID.randomUUID().toString();
            map.put(keys[i],UUID.randomUUID().toString());
        }
        System.out.println("Hashmap insert time : " +(System.currentTimeMillis()-start));

        //Hashmap read
        start=System.currentTimeMillis();
        for (int i=0;i<size;i++){
            index=random.nextInt(size);
            map.get(index);
        }
        System.out.println("Hashmap read time : " +(System.currentTimeMillis()-start));

    }
}
